<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    #main{
  width:1000px;
  margin:auto;
  }
  #smallpic{
  height:120px; 
  }
  img{
  float:left; 
  margin-right:10px; 
  margin-bottom:10px;
  }
  #smallpic img:hover{
    cursor:pointer;
  }
  .pb {
    border:3px solid red;
  }
    </style>
</head>
<body>
    <div id="main">
        <div id="smallpic">
            <img src="./images/1.jpg" class="test" width="180" height="100" />
            <img src="./images/2.jpg" class="test" width="180" height="100" />
            <img src="./images/3.jpg" class="test" width="180" height="100" />
            <img src="./images/4.jpg" class="test" width="180" height="100" />
            <img src="./images/5.jpg" class="test" width="180" height="100" />
        </div>
        <div>
            <img src="./images/0.jpg" id="bigpic" />
        </div>
    </div>
</body>
<script>
    var smallpic = document.getElementById("smallpic");
    var imgList = document.getElementsByTagName("img");
    var bigpic = document.getElementById("bigpic");
    for(var i=0;i<imgList.length;i++){
        imgList[i].onclick = function(){
            for(var j=0;j<imgList.length;j++){
                var classStr = imgList[j].getAttribute("class");
                var classArr = classStr.split(" ");
                if(classArr.indexOf("pb") >= 0){
                    var index = classArr.indexOf("pb");
                    classArr.splice(index,1);
                    var str = classArr.join(" ");
                    imgList[j].className = str;
                }else{
                    continue;
                }
            }
            this.className = "pb";
            //切换大图的src
            var imgSrc = this.getAttribute("src");
            bigpic.setAttribute("src",imgSrc);
            
        }
    }
    
</script>
</html>